﻿// ===============================================================================
// RegexRuleTest.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Rules.Tests
{
    using System;
    using EOS.Framework.Rules;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for RegexRuleTest and is intended
    /// to contain all RegexRuleTest Unit Tests
    /// </summary>
    [TestClass()]
    public class RegexRuleTest
    {
        private TestContext testContextInstance;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        /// A test for RegularExpression.
        /// </summary>
        [TestMethod()]
        public void RegularExpressionTest()
        {
            RegexRule target = new RegexRule("Description", "Regex"); 
            target.RegularExpression = "NewRegex";

            Assert.AreEqual("NewRegex", target.RegularExpression);
        }

        /// <summary>
        /// A test for RegularExpression. Regular expression cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RegularExpressionNullValueExceptionTest()
        {
            RegexRule target = new RegexRule("Description", "Regex");
            target.RegularExpression = null;
        }

        /// <summary>
        /// A test for RegularExpression. Regular expression cannot be empty.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RegularExpressionEmptyValueExceptionTest()
        {
            RegexRule target = new RegexRule("Description", "Regex");
            target.RegularExpression = string.Empty;
        }

        /// <summary>
        /// A test for RegularExpression. Regular expression cannot contain only blanks.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RegularExpressionBlanksOnlyValueExceptionTest()
        {
            RegexRule target = new RegexRule("Description", "Regex");
            target.RegularExpression = " ";
        }

        /// <summary>
        /// A test for RegexRule Constructor
        /// </summary>
        [TestMethod()]
        public void RegexRuleConstructorTest()
        {
            string description = "Description";
            string regularExpression = "Regex"; 

            RegexRule target = new RegexRule(description, regularExpression);

            Assert.AreEqual(description, target.Description, "Description not set correctly");
            Assert.AreEqual(regularExpression, target.RegularExpression, "Regular expression not set correctly.");
        }

        /// <summary>
        /// A test for RegexRule Constructor. Regular expression cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RegexRuleConstructorNullRegularExpressionExceptionTest()
        {
            new RegexRule("Description", null);
        }

        /// <summary>
        /// A test for RegexRule Constructor. Regular expression cannot be empty.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RegexRuleConstructorEmptyRegularExpressionExceptionTest()
        {
            new RegexRule("Description", string.Empty);
        }

        /// <summary>
        /// A test for RegexRule Constructor. Regular expression cannot contain only blanks.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void RegexRuleConstructorBlanksOnlyRegularExpressionExceptionTest()
        {
            new RegexRule("Description", " ");
        }
    }
}
